package example;

import com.dto.DTO;
import com.entity.Teacher;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.utils.JacksonUtils;

import java.lang.reflect.Field;

public class Json {
    public static<T> String getSex(T t) throws IllegalAccessException, NoSuchFieldException {
        Class clazz = t.getClass();
        Field sex = clazz.getDeclaredField("sex");
        sex.setAccessible(true);
        return sex.get(t).toString();
    }

    public static void main(String[] args) throws JsonProcessingException, NoSuchFieldException, IllegalAccessException {
//        Teacher teacher = new Teacher();
//        teacher.setTno("0001");
//        teacher.setTname("zs");
//        ObjectMapper objectMapper = new ObjectMapper();//把java对象转换为json字符串的工具类，json jackson gson
//        System.out.println(objectMapper.writeValueAsString(teacher));
//        String jsonStr = "{\"tno\":\"0002\",\"tname\":\"ls\",\"sex\":\"男\",\"birthday\":null,\"jointime\":null,\"area\":null,\"imgsrc\":null,\"pwd\":null,\"tdesc\":null,\"scs\":null}";
//        Teacher teacher1 = objectMapper.readValue(jsonStr, Teacher.class);
//        System.out.println(teacher1.getTname());



//        Student student = new Student();
//        student.setName("zs");
//        student.setSex("男");
//
//        Teacher teacher = new Teacher();
//        teacher.setTname("zs");
//        teacher.setSex("女");
//        System.out.println( TeacherServiceImpl.getSex(teacher));



        String dtoString = "{\"@class\":\"com.dto.DTO\",\"code\":200,\"msg\":\"查询学生成功\",\"t\":null,\"tList\":[\"java.util.ArrayList\",[{\"@class\":\"com.entity.Teacher\",\"tno\":\"0001\",\"tname\":\"赵世晨1\",\"sex\":\"女\",\"birthday\":[\"java.util.Date\",223689600000],\"jointime\":[\"java.util.Date\",1146441600000],\"area\":\"四川省\",\"imgsrc\":\"\",\"pwd\":\"\",\"tdesc\":\"硕士研究生学历\",\"scs\":null},{\"@class\":\"com.entity.Teacher\",\"tno\":\"0002\",\"tname\":\"赵世晨\",\"sex\":\"男\",\"birthday\":[\"java.util.Date\",223603200000],\"jointime\":[\"java.util.Date\",1146441600000],\"area\":\"内蒙古自治区赤峰市松山区,150404\",\"imgsrc\":\"2021-05-06-02-54-37.jpg\",\"pwd\":\"\",\"tdesc\":\"硕士研究生学历\",\"scs\":null},{\"@class\":\"com.entity.Teacher\",\"tno\":\"0003\",\"tname\":\"李广\",\"sex\":\"男\",\"birthday\":[\"java.util.Date\",433814400000],\"jointime\":[\"java.util.Date\",1154390400000],\"area\":\"河北省邯郸市邯山区,130402\",\"imgsrc\":null,\"pwd\":null,\"tdesc\":\"优秀青年教师\",\"scs\":null},{\"@class\":\"com.entity.Teacher\",\"tno\":\"0004\",\"tname\":\"曾海阁1\",\"sex\":\"男\",\"birthday\":[\"java.util.Date\",131328000000],\"jointime\":[\"java.util.Date\",1170288000000],\"area\":\"成都\",\"imgsrc\":\"\",\"pwd\":\"\",\"tdesc\":\"优秀青年教师\",\"scs\":null},{\"@class\":\"com.entity.Teacher\",\"tno\":\"0005\",\"tname\":\"张兰\",\"sex\":\"男\",\"birthday\":[\"java.util.Date\",478483200000],\"jointime\":[\"java.util.Date\",1177977600000],\"area\":\"河北省秦皇岛市山海关区,130303\",\"imgsrc\":\"2021-05-07-05-07-21121.jpg\",\"pwd\":\"\",\"tdesc\":\"优秀青年教师\",\"scs\":null},{\"@class\":\"com.entity.Teacher\",\"tno\":\"0006\",\"tname\":\"夏宁静\",\"sex\":\"女\",\"birthday\":[\"java.util.Date\",457488000000],\"jointime\":[\"java.util.Date\",1241136000000],\"area\":\"成都\",\"imgsrc\":null,\"pwd\":null,\"tdesc\":\"深受学生喜爱\",\"scs\":null},{\"@class\":\"com.entity.Teacher\",\"tno\":\"0007\",\"tname\":\"焦成\",\"sex\":\"男\",\"birthday\":[\"java.util.Date\",444441600000],\"jointime\":[\"java.util.Date\",1209600000000],\"area\":\"贵阳\",\"imgsrc\":null,\"pwd\":null,\"tdesc\":\"技术专家\",\"scs\":null},{\"@class\":\"com.entity.Teacher\",\"tno\":\"0008\",\"tname\":\"王静\",\"sex\":\"女\",\"birthday\":[\"java.util.Date\",444441600000],\"jointime\":[\"java.util.Date\",1220313600000],\"area\":\"成都\",\"imgsrc\":null,\"pwd\":null,\"tdesc\":\"深受学生喜爱\",\"scs\":null},{\"@class\":\"com.entity.Teacher\",\"tno\":\"0011\",\"tname\":\"zhangsan2\",\"sex\":null,\"birthday\":null,\"jointime\":null,\"area\":\"男\",\"imgsrc\":\"\",\"pwd\":\"\",\"tdesc\":\"ujj\",\"scs\":null},{\"@class\":\"com.entity.Teacher\",\"tno\":\"0012\",\"tname\":\"zhangsan2\",\"sex\":\"男\",\"birthday\":null,\"jointime\":null,\"area\":\"男\",\"imgsrc\":null,\"pwd\":null,\"tdesc\":null,\"scs\":null}]],\"obj\":{\"@class\":\"com.page.PageInfo\",\"pageSize\":10,\"pageCount\":2,\"itemCount\":17,\"currPage\":1,\"offset\":0,\"isPage\":false,\"page\":false}}";

        String dtoSimpleString = "{\"@class\":\"com.dto.DTO\",\"code\":200,\"msg\":\"查询学生成功\"}";
        DTO<Teacher> dto = JacksonUtils.deserializeDTO(dtoString,DTO.class,Teacher.class);




       String jsonString="{\"mac_algorithm\":\"hmac-sha-1\",\"mac_key\":\"4d48e69cd33241bfbac641e01dda66c9\",\"token_type\":\"mac\",\"user\":{\"id\":586715549,\"name\":\"陈琦\",\"avatar\":[{\"type\":\"avatar\",\"url\":\"http://head.xiaonei.com/photos/0/0/men_head.gif\"},{\"type\":\"tiny\",\"url\":\"http://head.xiaonei.com/photos/0/0/men_tiny.gif\"},{\"type\":\"main\",\"url\":\"http://head.xiaonei.com/photos/0/0/men_main.gif\"},{\"type\":\"large\",\"url\":\"http://head.xiaonei.com/photos/0/0/men_main.gif\"}]},\"access_token\":\"474449|2.dYgaaycHv6w2CQ0K3X5HUijL8b4B6P1m.586715549.1421028736042\"}";

    }
}
